package com.jereh.weibo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jereh.weibo.R;
import com.jereh.weibo.circleimageview.CircleImageView;
import com.jereh.weibo.entity.Message;

import java.util.List;

/**
 * Created by Administrator on 2016/12/5.
 */
public class MessageAdapter extends BaseAdapter{

    private Context ctx;
    private List<Message> list;

    public MessageAdapter(Context ctx, List<Message> list) {
        this.ctx = ctx;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if(convertView==null){
            convertView= LayoutInflater.from(ctx).inflate(R.layout.message,null,false);
            holder=new ViewHolder();
            holder.tou=(CircleImageView)convertView.findViewById(R.id.tou);
            holder.title=(TextView)convertView.findViewById(R.id.title11);
            holder.content=(TextView)convertView.findViewById(R.id.content);
            holder.time=(TextView)convertView.findViewById(R.id.time);
            convertView.setTag(holder);
        }else {
            holder=(ViewHolder)convertView.getTag();
        }
        holder.tou.setImageResource(list.get(position).getTou());
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getContent());
        holder.time.setText(list.get(position).getTime());
        return convertView;
    }
    static class ViewHolder{
        CircleImageView tou;
        TextView title;
        TextView content;
        TextView time;
    }
}
